#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<sys/wait.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int main(int argc, char* args[])
{
	int pid = fork();
	if(pid < 0){
		perror("fork error");
		exit(1);
	}
	else if(pid){
		int status;
		int pid;
		if((pid = wait(&status)) < 0){
			perror("wait error");
			exit(1);
		}

		if(WIFEXITED(status)){
			printf("child return %d\n", WEXITSTATUS(status));
		}
		else if(WIFSIGNALED(status)){
			printf("child kill by signal %d\n", WTERMSIG(status));
		}

	}
	else if(!pid){
		printf("this is child:%d, parent is %d\n",getpid(), getppid());
		sleep(1000);
		return 1;
	}
	exit(0);
}

